<?php
/**
 * supCategory 
 * - Define class SCategory
 * @author ANHTAM
 * @since 1.1 - Sep 27, 2011
 * $Id: $
 */
include_once(DOCUMENT_ROOT . "/lib/core/BaseProcess.class.php");
class SanphamSCategory extends BaseProcess {
	public function __construct() {
		parent::__construct("sp_sub_category");
		$this->primaryKeyName = "id";
	}

	public function getListAll($danhmuc_id = '', $iddm = '', $flag = false) {
		$sql = "SELECT id, iddm, name, code FROM " . $this->tableName. " WHERE 1=1";
		if ($danhmuc_id != '') {
			$sql .= " AND danhmuc_id = " . $danhmuc_id;
		}
		if ($iddm != '') {
			$sql .= " AND iddm=" . $iddm;
		}
		if ($flag) {
			$sql .= " AND name <> ''";
		}
		$sql .= " ORDER BY seq DESC";
		$rs = $this->execute($sql, ADODB_FETCH_ASSOC);
        $data = array();
        if ($rs) {
            while (! $rs->EOF && $item = $rs->FetchRow()) {
                $data[] = $item;
            }
        }
        return $data;
	}
	
	public function checkTonTai($danhmuc_id = '', $iddm = '', $flag = false) {
		$sql = "SELECT count(*) as count_id FROM " . $this->tableName . " WHERE danhmuc_id = '" . $danhmuc_id . "' AND iddm ='" . $iddm . "'";
		if ($flag) {
			$sql .= " AND name <> ''";
		}
		$rs = $this->execute($sql, ADODB_FETCH_ASSOC);
		return ($rs && $rs->fields['count_id'] > 0) ? false : true;
	}
	
	public function getIDDMC($danhmuc_id = '', $iddm = '', $flag = false) {
		$sql = "SELECT id FROM " . $this->tableName . " WHERE danhmuc_id = '" . $danhmuc_id . "' AND iddm ='" . $iddm . "'";
		if ($flag) {
			$sql .= " AND name <> ''";
		}
		$rs = $this->execute($sql, ADODB_FETCH_ASSOC);
		return ($rs) ? $rs->fields['id'] : "";
	}
	
	
}
?>